package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Caringwelfare.BenefitActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.GoodlistitemBean;

import java.util.List;

public class CaringwelfarelistApter extends RecyclerView.Adapter<CaringwelfarelistApter.Myhot> {
    private Context context ;
    private View view;
    private List<GoodlistitemBean.RowsBean> list;

    public CaringwelfarelistApter(Context context, List<GoodlistitemBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_caringwelfarelist,null);
        return new CaringwelfarelistApter.Myhot(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Myhot holder, int position) {
        Glide.with(context).load("http://124.93.196.45:10001"+list.get(position).getImgUrl()).into(holder.imageView);
        holder.projectNameTextView.setText("公益项目名称:"+list.get(position).getName());
        holder.organizationTextView.setText("发布组织:"+list.get(position).getAuthor());
        holder.donorsTextView.setText("捐赠人数:"+String.valueOf(list.get(position).getDonateCount()));
        holder.fundsTextView.setText("已筹善款:"+String.valueOf(list.get(position).getMoneyNow()));
        holder.li_acatingwe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BenefitActivity.class);
                intent.putExtra("listID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final ImageView imageView;
        private final TextView projectNameTextView;
        private final TextView organizationTextView;
        private final TextView donorsTextView;
        private final TextView fundsTextView;
        private final LinearLayout li_acatingwe;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            projectNameTextView = itemView.findViewById(R.id.projectNameTextView);
            organizationTextView = itemView.findViewById(R.id.organizationTextView);
            donorsTextView = itemView.findViewById(R.id.donorsTextView);
            fundsTextView = itemView.findViewById(R.id.fundsTextView);
            li_acatingwe = itemView.findViewById(R.id.li_acatingwe);
        }
    }
}
